/*
 * 搜索联系人
 */
package address;

import static address.People.getPinyin;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
public class SearchCon {
    ArrayList L=new ArrayList();
    ArrayList contacts=null;

    
    public SearchCon(String tip,ArrayList contacts){
        this.contacts=contacts;
        People p=null;
        if (tip.matches("[\\u4E00-\\u9FA5]+")) {
            //如果输入是中文，直接字符串匹配搜索 
            for (int i = 0; i < contacts.size(); i++) {
                p = (People) contacts.get(i);               
                if (p.name.contains(tip)) {
                    L.add(p);
                }                       
            }                 
        }
        
        else if(tip.matches("[a-zA-Z]+")) {
            //英文
             for (int i = 0; i < contacts.size(); i++) {
                p = (People) contacts.get(i);
                //将人名转换成拼音
                String pinyin = p.makeStringByStringSet(getPinyin(p.name)) ;
                System.out.println(pinyin);
                if (pinyin.contains(tip)) {
                    L.add(p);
                }  
            }            
        }
        
        else if(tip.matches("[0-9]+")){
            //数字
            for (int i = 0; i < contacts.size(); i++) {
                p = (People) contacts.get(i);
                for (int j = 0; j < p.phone.size(); j++) {
                   Phone phone = (Phone) p.phone.get(j);
                   if (phone.number.contains(tip)) {
                        L.add(p);
                    }
                }
                
            }
        }
        
        else {
            //其他
            System.out.println("cuowu");
        }
      
        
    }
    
    ArrayList getsearchresult(){
        return L;
    }
    
}
